<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>interp2d</title>
  </head>
  <body bgcolor="#FFFFFF">
    <center>Scilab Function</center>
    <div align="right">Last update : 11/03/2005</div>
    <p>
      <b>interp2d</b> - bicubic spline (2d) evaluation function</p>
    <h3>
      <font color="blue">Calling Sequence</font>
    </h3>
    <dl>
      <dd>
        <tt>[zp[,dzpdx,dzpdy[,d2zpdxx,d2zpdxy,d2zpdyy]]]=interp2d(xp,yp,x,y,C [,out_mode])</tt>
      </dd>
    </dl>
    <h3>
      <font color="blue">Parameters</font>
    </h3>
    <ul>
      <li>
        <tt>
          <b>xp, yp</b>
        </tt>: real vectors or matrices of same size</li>
      <li>
        <tt>
          <b>x,y,C</b>
        </tt>: real vectors defining a bicubic spline or sub-spline function 
                (called <tt>
          <b>s</b>
        </tt> in the following)</li>
      <li>
        <tt>
          <b>out_mode</b>
        </tt>: (optional) string defining the evaluation of <tt>
          <b>s</b>
        </tt> outside 
                [x(1),x(nx)]x[y(1),y(ny)]</li>
      <li>
        <tt>
          <b>zp</b>
        </tt>: vector or matrix of same format than <tt>
          <b>xp</b>
        </tt> and <tt>
          <b>yp</b>
        </tt>, elementwise 
                evaluation of <tt>
          <b>s</b>
        </tt> on these points.</li>
      <li>
        <tt>
          <b>dzpdx, dzpdy</b>
        </tt>: vectors (or matrices) of same format than <tt>
          <b>xp</b>
        </tt> and <tt>
          <b>yp</b>
        </tt>, elementwise
                evaluation of the first derivatives of <tt>
          <b>s</b>
        </tt> on these points.</li>
      <li>
        <tt>
          <b>d2zpdxx, d2zpdxy, d2zpdyy</b>
        </tt>: vectors (or matrices) of same format than <tt>
          <b>xp</b>
        </tt> and <tt>
          <b>yp</b>
        </tt>, elementwise
                evaluation of the second derivatives of <tt>
          <b>s</b>
        </tt> on these points.</li>
    </ul>
    <h3>
      <font color="blue">Description</font>
    </h3>
    <p>
    Given three vectors <tt>
        <b>(x,y,C)</b>
      </tt> defining a bicubic spline or sub-spline function
    (see <a href="splin2d.htm">
        <tt>
          <b>splin2d</b>
        </tt>
      </a>) this function evaluates <em>s</em> (and <em>ds/dx, ds/dy, d2s/dxx, d2s/dxy,
    d2s/dyy</em> if needed) at <em>(xp(i),yp(i))</em> :
    </p>
    <pre>
      zp(i) = s(xp(i),yp(i))   
      dzpdx(i) = ds/dx(xp(i),yp(i))
      dzpdy(i) = ds/dy(xp(i),yp(i))  
      d2zpdxx(i) = d2s/dx2(xp(i),yp(i))
      d2zpdxy(i) = d2s/dxdy(xp(i),yp(i))  
      d2zpdyy(i) = d2s/dy2(xp(i),yp(i))
         </pre>
    <p>
    The <tt>
        <b>out_mode</b>
      </tt> parameter defines the evaluation rule for extrapolation,
    i.e. for <em>(xp(i),yp(i)) not in [x(1),x(nx)]x[y(1),y(ny)]</em>: 
    </p>
    <dd>
      <li>
        <b>
          <font color="maroon">"by_zero"</font>
        </b>: an extrapolation by zero is done</li>
      <li>
        <b>
          <font color="maroon">"by_nan"</font>
        </b>: extrapolation by Nan</li>
      <li>
        <b>
          <font color="maroon">"C0"</font>
        </b>: the extrapolation is defined as follows :<pre>
     s(x,y) = s(proj(x,y)) where proj(x,y) is nearest point 
                           of [x(1),x(nx)]x[y(1),y(ny)] from (x,y)
         </pre>
      </li>
      <li>
        <b>
          <font color="maroon">"natural"</font>
        </b>: the extrapolation is done by using the nearest bicubic-patch from (x,y).</li>
      <li>
        <b>
          <font color="maroon">"periodic"</font>
        </b>: <tt>
          <b>s</b>
        </tt> is extended by periodicity.</li>
    </dd>
    <h3>
      <font color="blue">Examples</font>
    </h3>
    <pre>
// see the examples of splin2d

// this example shows some different extrapolation features
// interpolation of cos(x)cos(y)
n = 7;  // a n x n interpolation grid
x = linspace(0,2*%pi,n); y = x;
z = cos(x')*cos(y);
C = splin2d(x, y, z, "periodic");

// now evaluate on a bigger domain than [0,2pi]x [0,2pi]
m = 80; // discretisation parameter of the evaluation grid
xx = linspace(-0.5*%pi,2.5*%pi,m); yy = xx;
[XX,YY] = ndgrid(xx,yy);
zz1 = interp2d(XX,YY, x, y, C, "C0");
zz2 = interp2d(XX,YY, x, y, C, "by_zero");
zz3 = interp2d(XX,YY, x, y, C, "periodic");
zz4 = interp2d(XX,YY, x, y, C, "natural");
xbasc()
subplot(2,2,1)
  plot3d(xx, yy, zz1, flag=[2 6 4])
  xtitle("extrapolation with the C0 outmode")
subplot(2,2,2)
  plot3d(xx, yy, zz2, flag=[2 6 4])
  xtitle("extrapolation with the by_zero outmode")
subplot(2,2,3)
  plot3d(xx, yy, zz3, flag=[2 6 4])
  xtitle("extrapolation with the periodic outmode")
subplot(2,2,4)
  plot3d(xx, yy, zz4, flag=[2 6 4])
  xtitle("extrapolation with the natural outmode")
xselect()
 </pre>
    <h3>
      <font color="blue">See Also</font>
    </h3>
    <p>
      <a href="splin2d.htm">
        <tt>
          <b>splin2d</b>
        </tt>
      </a>,&nbsp;&nbsp;</p>
    <h3>
      <font color="blue">Author</font>
    </h3>
    <p>
    B. Pincon
  </p>
  </body>
</html>
